#!/usr/bin/perl
#VR
#tikrina ar ligandai turi S ir yra netoli ZN is ZN.pdb

use Chemistry::MacroMol;
use Chemistry::File::PDB;

if(!-d "geri_ligandai") {
mkdir("geri_ligandai", 0777);
}

while (@ARGV[$x]) {
$macromol = Chemistry::MacroMol->read("@ARGV[$x]");
print "\nTikrinamas ", @ARGV[$x], ": ";
#imam Zn geroj padetyje
$znmol = Chemistry::MacroMol->read("ZN.pdb");
tikrinti();
$x++;
}

sub tikrinti {
@all_atoms = $macromol->atoms;
$a = 0;
@S = ();
while (@all_atoms[$a]) {
push(@S, @all_atoms[$a]) if (@all_atoms[$a]->symbol eq 'S');
$a++;
}

#imam Zn
$Zn = $znmol->atoms_by_name('ZN');

@d = ();
$b = 0;
while (@S[$b]) {
#print @S[$b]->distance($Zn), " ";
push (@d, @S[$b]->distance($Zn));
$b++;
}

sort (@d);
#print @d[0], " A, ";
if (@d[0] < 5 && @d[0] > 0) {
print "geras";
$h = $ARGV[$x];
system ("mv $h geri_ligandai/");
}
print "\n";
}
